from app.model.user_model import UserModel
from app.controller.validate.user_validate import UserPutValidate
from .shoutcut_import import *

bp = V1BluePoint('users', __name__, url_prefix='')


@bp.route('user', methods=['PUT'])
@validate_form(UserPutValidate)
@user_require
def put_user():
    """修改用户"""
    uid = g.uid
    user = UserModel.query.filter_by(id=uid).first()
    if not user:
        return error_json(ResponseCode.RESOURCE_NOT_FOUND, '找不到指定的用户')
    user.update(request.json)
    sqla_db.session.commit()
    return success_json()